<template>
    <base-com>
      <div class="system">
        <div class="tab_nav">
          <div class="tabs_tab" :class="{height_light:flag ==='huiyuan'}" @click="select_tab('huiyuan')">
            会员管理
          </div>
          <div class="tabs_tab" :class="{height_light:flag ==='ziguanli'}" @click="select_tab('ziguanli')">
            子管理员管理
          </div>
          <div class="tabs_tab" :class="{height_light:flag ==='canshu'}" @click="select_tab('canshu')">
            参数设置
          </div>
          <div class="extra">
            <div class="huiyuan" v-show="flag ==='huiyuan'" @click="client_modall=true">
              <p class="ico_add"></p>
              <label>添加会员</label>
            </div>
            <div class="zihuiyuan" v-show="flag ==='ziguanli'" @click="add_client_modall =true;create_new_googlekey()">
              <p class="ico_add"></p>
              <label>添加子管理员</label>
            </div>
          </div>
        </div>
        <div class="tabs_bar">
          <div class="tabs_container" v-show="flag ==='huiyuan'">
            <Table :columns="client_columns" :data="client_data" stripe disabled-hover></Table>
          </div>
          <div class="tabs_container" v-show="flag ==='ziguanli'">
            <Table :columns="member_columns" :data="member_data" stripe disabled-hover></Table>
          </div>
          <div class="tabs_container" v-show="flag ==='canshu'">
            <Table :columns="strategy_parameter_columns" :data="strategy_parameter_data" stripe disabled-hover></Table>
            <!--<Table :columns="contract_parameter_columns" :data="contract_price_data" stripe disabled-hover></Table>-->
          </div>
        </div>
        <div class="moadl">
          <Modal
            v-model="client_modall"
            :title="client_modall_title"
            :ok-text = "client_modall_ok"
            @on-ok ="client_add"
            @on-cancel ="client_cancel"
            :loading ='true'
            width="400">
            <div>
              <Form>
                <FormItem label="用户名" :label-width="100" style="margin-bottom: 10px;">
                  <Input v-model="add_client_data.client_name" ></Input>
                </FormItem>
                <FormItem label="	APIKey" :label-width="100" style="margin-bottom: 10px;">
                  <Input v-model="add_client_data.apikey" ></Input>
                </FormItem>
                <FormItem label="SecertKey" :label-width="100" style="margin-bottom: 10px;">
                  <Input v-model="add_client_data.secretkey" ></Input>
                </FormItem>
                <FormItem label="合约选择" :label-width="100" style="margin-bottom: 10px;">
                  <Select v-model="add_client_data.account_type" style="width: 268px">
                    <Option value="永续">永续</Option>
                    <Option value="定期">定期</Option>
                  </Select>
                </FormItem>
              </Form>
            </div>
          </Modal>
          <Modal
            v-model="delete_modall1"
            ok-text="确定"
            cancel-text="取消"
            @on-ok="delete_client()">
            <p>确定要删除吗？</p>
          </Modal>

          <Modal
            v-model="add_client_modall"
            :title="add_client_modall_title"
            :ok-text = "add_client_modall_ok"
            :mask-closable = false
            @on-ok ="add_client_add"
            @on-cancel ="add_client_cancel"
            :loading ='true'
            width="400">
            <div>
              <Form>
                <FormItem label="名称" :label-width="50" style="margin-bottom: 10px;">
                  <Input v-model="add_member_data.trader" ></Input>
                </FormItem>
                <FormItem label="秘钥" :label-width="50" style="margin-bottom: 10px;">
                  <Input v-model="add_member_data.googlecode" disabled="disabled" style="width: 250px"></Input>
                  <Button  type="primary"
                           v-clipboard:copy="add_member_data.googlecode"
                           v-clipboard:success="onCopy"
                           v-clipboard:error="onError">复制</Button>
                  <!--<Button type="primary"  v-clipboard:success="onCopy">复制</Button>-->
                </FormItem>
                <FormItem label="输入6位数验证码验证" :label-width="150" style="margin-bottom: 10px;">
                  <Input v-model="add_member_data.googlekey" ></Input>
                </FormItem>
              </Form>
            </div>
          </Modal>
          <Modal
            v-model="google_modall"
            :title="google_modall_title"
            :ok-text = "google_modall_ok"
            @on-ok ="google_add"
            @on-cancel ="google_cancel"
            :mask-closable = false
            :loading ='true'
            width="400">
            <div>
              <Form>
                <FormItem label="名称" :label-width="50" style="margin-bottom: 10px;">
                  <Input v-model="add_member_data.trader" disabled="disabled"></Input>
                </FormItem>
                <FormItem label="秘钥" :label-width="50" style="margin-bottom: 10px;">
                  <Input v-model="add_member_data.googlecode" disabled="disabled" style="width: 250px"></Input>
                  <Button  type="primary"
                           v-clipboard:copy="add_member_data.googlecode"
                           v-clipboard:success="onCopy"
                           v-clipboard:error="onError">复制</Button>
                  <!--<Button type="primary"  v-clipboard:success="onCopy">复制</Button>-->
                </FormItem>
                <FormItem label="输入6位数验证码验证" :label-width="150" style="margin-bottom: 10px;">
                  <Input v-model="add_member_data.googlekey" ></Input>
                </FormItem>
              </Form>
            </div>
          </Modal>
          <Modal
            v-model="assignUser_modall"
            :title="assignUser_modall_title"
            :ok-text = "assignUser_modall_ok"
            @on-ok ="assignUser_update"
            @on-cancel ="assignUser_cancel"
            :loading ='true'
            width="460">
            <div>
              <Transfer
                :data="temp_list_undistributed"
                :targetKeys="temp_list_distributed"
                :render-format="assignUser_render"
                @on-change="assignUser_handleChange"></Transfer>
            </div>
          </Modal>
          <Modal
            v-model="resetPasswords_modall"
            ok-text="确定"
            cancel-text="取消"s
            title = "重置密码"
            @on-ok="resetPasswords()">
            <p>确认将{{reset_trader}}密码重置？</p>
          </Modal>
          <Modal
            v-model="end_modall"
            :title="end_modall_title"
            @on-ok ="end"
            :loading ='true'
            width="440">
            <p>该子管理员的用户仓位全部平仓，确认执行？</p>
          </Modal>
          <Modal
            v-model="end_all_modall"
            :title="end_modall_title"
            @on-ok ="endAll"
            :loading ='true'
            width="440">
            <p>删除所有管理员的用户仓位全部平仓，确认执行？</p>
          </Modal>
          <Modal
            v-model="delete_modall2"
            ok-text="确定"
            cancel-text="取消"
            @on-ok="select_remove()">
            <p>确定要删除吗？</p>
          </Modal>
          <Modal
            v-model="trader_client_modall"
            :footer-hide= true
            title="已分配用户"
            width="200"
          >
            <p v-for="client in list_trader_client">{{client[0]}}</p>
          </Modal>

          <Modal
            v-model="strategy_parameter_modall"
            :title="strategy_parameter_modall_title"
            :ok-text = "strategy_parameter_modall_ok"
            @on-ok ="strategy_parameter_save"
            @on-cancel ="strategy_parameter_cancel"
            :loading ='true'
            width="400">
            <div>
              <Form>
                <FormItem label="开仓手续费率" :label-width="180" style="margin-bottom: 10px;">
                  <Input v-model="add_strategy_parameter_data.open_rate" ></Input>
                </FormItem>
                <FormItem label="平仓手续费率" :label-width="180" style="margin-bottom: 10px;">
                  <Input v-model="add_strategy_parameter_data.close_rate" ></Input>
                </FormItem>
                <FormItem label="系统响应时间" :label-width="180" style="margin-bottom: 10px;">
                  <Input v-model="add_strategy_parameter_data.system_response_time" >
                  <span slot="append"  style="width: 80px" >秒</span>
                  </Input>
                </FormItem>
              </Form>
            </div>
          </Modal>
          <Modal
            v-model="contract_parameter_modall"
            :title="contract_parameter_modall_title"
            :ok-text = "contract_parameter_modall_ok"
            @on-ok ="contract_parameter_save"
            @on-cancel ="contract_parameter_cancel"
            :loading ='true'
            width="400">
            <div>
              <Form>
                <FormItem label="合约" :label-width="80" style="margin-bottom: 10px;">
                  <Input v-model="add_contract_parameter_data.contract"  disabled="disabled"></Input>
                </FormItem>
                <FormItem label="价格种类" :label-width="80" style="margin-bottom: 10px;">
                  <Select v-model="add_contract_parameter_data.price_type">
                    <Option value="price_index">指数价</Option>
                    <Option value="price_new">最新价</Option>
                  </Select>
                </FormItem>
              </Form>
            </div>
          </Modal>

          <Modal
            v-model="update_client_modall"
            :title="update_client_modall_title"
            :mask-closable = "false"
            @on-ok ="update_client_save"
            @on-cancel ="update_client_cancel"
            :loading ='true'
            width="400">
            <div>
              <Form>
                <FormItem label="用户名" :label-width="130" style="margin-bottom: 10px;">
                  <Input v-model="update_client.client_name" disabled="disabled"style="width: 210px"></Input>
                </FormItem>
                <FormItem label="最低净值" :label-width="130" style="margin-bottom: 10px;">
                  <Input v-model="update_client.lowest_net_worth" style="width: 210px"></Input>
                </FormItem>
                <FormItem label="最低净值触发类型" :label-width="130" style="margin-bottom: 10px;">
                  <Select v-model="update_client.lowest_net_worth_type" style="width: 210px">
                    <Option value="被动">被动</Option>
                    <Option value="市价">市价</Option>
                  </Select>
                </FormItem>
              </Form>
            </div>
          </Modal>
        </div>
      </div>
    </base-com>
</template>

<script>
  import {
    getListClient,
    insertClient,
    deleteClient,
    updateClient,
  } from '@/api/client'
  import {
    getListTrader,
    getListTraderClient,
    insertTrader,
    updateTraderGooglekey,
    getListTraderNone,
    defaultTraderPassword,
    end,
    endAll,
    deleteTrader,
    updateClientTrader,
  } from '@/api/trader'
  import {
    getConfigBasic,
    getConfigNowOrIndex,
    updateConfigBasic,
    updateConfigNowOrIndex,
  } from '@/api/config'
  import { mapGetters } from 'vuex'
  import {
    isNumberAndNone,
    isPrecision,
  } from '@/libs/tools'
    import BaseCom from "../../components/base-com/base-com";
    export default {
        name: "system",
      components: {BaseCom},
      data(){
          return{
            flag:'huiyuan',
            client_columns: [
              {
                title: '用户名',
                align:'center',
                key: 'client_name',

              },
              {
                title: '所属管理员',
                align:'center',
                key: 'trader'
              },
              {
                title: 'APIKey',
                key: 'apikey',
                align:'center',
                width:'350'
              },
              {
                title: 'SecertKey',
                key: 'secretkey',
                align:'center',
                width:'350'
              },
              {
                title: '可用',
                key: 'margin_available',
                align:'center',
                width:'200'
              },
              {
                title: '当前权益',
                key: 'swap_margin_balance',
                align:'center',
                width:'150'
              },
              {
                title: '冻结资产',
                align:'center',
                width:'120',
                render:(h,params)=>{

                  if(Number(params.row.swap_margin_position)=== 0 &&Number(params.row.margin_frozen === 0 )){
                    return h('span',{
                    },0)
                  }else {
                    return h('span',{
                    },(Number(params.row.swap_margin_position)+ Number(params.row.margin_frozen)).toFixed(7))
                  }
                }
              },
              {
                title: '最低净值',
                key: 'lowest_net_worth',
                align:'center',
                width:'100'
              },
              {
                title: '最低净值触发类型',
                key: 'lowest_net_worth_type',
                align:'center',
                width:'200'
              },
              {
                title: '操作',
                align:'center',
                key: 'operation',
                render: (h, params) => {
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'text',
                        size: 'small'
                      },
                      style:{
                        color:"rgb(103, 154, 247)"
                      },
                      on:{
                        click: () => {
                          console.log(params.row);
                          this.update_client_modall = true;
                          this.update_client =  JSON.parse(JSON.stringify(params.row));
                        }
                      }
                    }, '编辑'),
                    h('Button', {
                      props: {
                        type: 'text',
                        size: 'small'
                      },
                      style:{
                        color:"rgb(103, 154, 247)"
                      },
                      on:{
                        click: () => {
                          this.delete_modall1 =true;
                          this.deleteparam  = params.row;
                        }
                      }
                    }, '删除'),
                  ]);
                }
              },
            ],
            client_data: [],
            update_client: {
              client_name:'',
              APIKey:'',
              SecertKey:'',
              lowest_net_worth:'',
              lowest_net_worth_type:'市价',
            },
            update_client_modall:false,
            update_client_modall_title:'编辑会员',
            client_modall:false,
            client_modall_title:'添加会员',
            client_modall_ok:'添加',
            delete_modall1:false,
            delete_modall2:false,
            add_client_data:{
              client_name:'',
              apikey:'',
              secretkey:'',
              account_type:'永续',
            },
            deleteparam:'',//删除内容
            member_columns: [
              {
                title: '名称',
                key: 'trader',
                align:'center',
                width:'120'
              },
              {
                title: '用户数',
                key: 'client_number',
                align:'center',
                render: (h, params) => {
                  if(params.row.client_number !==0){
                    return h('div',
                      [
                        params.row.client_number,
                        h('Button', {
                          props: {
                            type: 'text',
                            size: 'small'
                          },
                          style:{
                            color:"rgb(103, 154, 247)"
                          },
                          on:{
                            click: () => {
                              this.getListTraderClient(params.row.trader)
                              this.trader_client_modall = true
                            }
                          }
                        }, '详情'),
                      ]);
                  }else {
                    return h('div', [
                      params.row.client_number
                    ]);
                  }
                }
              },
              {
                title: '操作',
                key: 'operation',
                align:'center',
                width: 500,
                render: (h, params) => {
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'text',
                        size: 'small'
                      },
                      style:{
                        color:"rgb(103, 154, 247)"
                      },
                      on:{
                        click: () => {
                          this.google_modall = true;
                          this.create_new_googlekey();
                          this.add_member_data.trader = params.row.trader;
                        }
                      }
                    }, '修改谷歌验证码'),
                    h('Button', {
                      props: {
                        type: 'text',
                        size: 'small'
                      },
                      style:{
                        color:"rgb(103, 154, 247)"
                      },
                      on:{
                        click: () => {
                          // this.getListTraderNone();
                          this.reset_trader = params.row.trader
                          this.getListTraderNone();
                          this.assignUser_modall = true;
                        }
                      }
                    }, '分配用户'),
                    h('Button', {
                      props: {
                        type: 'text',
                        size: 'small'
                      },
                      style:{
                        color:"rgb(103, 154, 247)"
                      },
                      on:{
                        click: () => {
                          this.reset_trader = params.row.trader
                          this.resetPasswords_modall = true;
                        }
                      }
                    }, '重置密码'),
                    h('Button', {
                      props: {
                        type: 'text',
                        size: 'small'
                      },
                      style:{
                        color:"rgb(103, 154, 247)"
                      },
                      on:{
                        click: () => {
                          this.reset_trader = params.row.trader
                          this.end_modall = true
                        }
                      }
                    }, '一键平仓'),
                    h('Button', {
                      props: {
                        type: 'text',
                        size: 'small'
                      },
                      style:{
                        color:"rgb(103, 154, 247)"
                      },
                      on:{
                        click: () => {
                          this.reset_trader = params.row.trader
                          this.delete_modall2 = true
                        }
                      }
                    }, '删除'),
                  ]);
                }
              },
            ],
            member_data: [],
            add_member_data: {
              trader:'',
              googlecode:'',
              googlekey:'',
            },
            add_client_modall:false,
            add_client_modall_title:'添加子管理员',
            add_client_modall_ok:'确认',
            google_modall:false,
            google_modall_title:'谷歌验证',
            google_modall_ok:'确认',
            googleCode:'',
            assignUser_modall:false,
            assignUser_modall_title:'分配用户',
            assignUser_modall_ok:'确认',
            update_assignUser_data:[],
            resetPasswords_modall:false,//重置密码
            reset_trader:'',
            end_modall:false,
            end_all_modall:false,
            end_modall_title:'一键平仓',
            delete_All_modall:false,
            list_trader_client:'',//所属管理会员（客户）列表
            trader_client_modall:false,
            temp_list_undistributed:[],//尚未分配管理员的会员
            temp_list_distributed:[],//分配管理员的会员
            contract_parameter_columns: [
              {
                title: '合约',
                key: 'contract',
                align:'center',

              },
              {
                title: '价格种类',
                key: 'price_type',
                align:'center',
              },
              {
                title: '操作',
                key: 'operation',
                align:'center',
                width:200,
                render: (h, params) => {
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'text',
                        size: 'small'
                      },
                      style:{
                        color:"rgb(103, 154, 247)"
                      },
                      on:{
                        click: () => {
                          this.contract_parameter_modall = true;
                          this.add_contract_parameter_data = JSON.parse(JSON.stringify(params.row ));
                        }
                      }
                    }, '编辑'),
                  ]);
                }
              },
            ],
            contract_price_data: [
              {
                symbol: "XBTUSD",
                fee: 0.00075,
                baseRiskValue: 200,
                riskAddValue: 100,
                basePositionMarginRate: 0.0035,
                baseInitMarginRate: 0.01,
                switching: 1,
                priceType: "指数价",
              },

            ],
            strategy_parameter_columns: [
              {
                title: '开仓手续费率',
                key: 'open_rate',
                align:'center',

              },
              {
                title: '平仓手续费率',
                key: 'close_rate',
                align:'center',
              },
              {
                title: '系统响应时间',
                key: 'system_response_time',
                align:'center',
              },
              {
                title: '操作',
                key: 'operation',
                align:'center',
                width:200,
                render: (h, params) => {
                  return h('div', [
                    h('Button', {
                      props: {
                        type: 'text',
                        size: 'small'
                      },
                      style:{
                        color:"rgb(103, 154, 247)"
                      },
                      on:{
                        click: () => {
                          this.strategy_parameter_modall = true;
                          this.add_strategy_parameter_data = JSON.parse(JSON.stringify(params.row ));
                        }
                      }
                    }, '编辑'),
                  ]);
                }
              },
            ],
            strategy_parameter_data: [],
            clientSelected:'',
            contractSelected: '',
            strategy_parameter_modall:false,
            strategy_parameter_modall_title:'策略参数设置',
            strategy_parameter_modall_ok:'编辑',
            add_strategy_parameter_data: [],
            contract_parameter_modall:false,
            contract_parameter_modall_title:'合约参数设置',
            contract_parameter_modall_ok:'编辑',
            add_contract_parameter_data: [],
          }
      },
      methods:{
        ...mapGetters([
          'get_client',
          'get_contract',
        ]),
        select_tab(name){
          this.flag = name;
          if(name === 'huiyuan'){
            this.get_list_client();
          }
          if(name === 'ziguanli'){
            this.getListTrader();
          }
          if(name ==='canshu'){
            this.get_strategy();
            this.get_contract();
          }
        },
        //获取会员列表
        get_list_client(){
          let params ={
          };
          getListClient(params).then(res=>{
            if(res.data.code === 1000){
              this.client_data = res.data.data;
              this.$Message.success('数据获取成功');
            }else{
              this.$Message.error('失败');
            }
          })
        },
        //添加会员
        client_add(){
          let params ={
            client_name: this.add_client_data.client_name,
            apikey: this.add_client_data.apikey,
            secretkey: this.add_client_data.secretkey,
            account_type: this.add_client_data.account_type,
          };
          if(params.client_name === '' || params.apikey === '' || params.secretkey === '' || params.account_type === ''){
            this.$Message.error('请检查参数');
            return;
          }
          if(params.client_name.length>64){
            this.$Message.error('用户名不能超过64位');
            return;
          }
          insertClient(params).then(res=>{
            this.client_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查添加会员");
              return;
            }
            if(res.data.code === 1000){
              this.$Message.success('添加成功');
              this.get_list_client();
            }else{
              this.$Message.error(res.data.data);
            }
            this.client_cancel()
          }).catch(res=>{
            this.$Message.error("发生502，请核查添加会员");
            return;
          })
        },
        //添加会员取消按钮
        client_cancel(){
          this.add_client_data = {
            client_name:'',
            apikey:'',
            secretkey:'',
            account_type:'永续',
          };
        },
        //删除会员
        delete_client(){
          let params ={
            client_name: this.deleteparam.client_name,
          };
          console.log(params)
          console.log(1)
          deleteClient(params).then(res=>{
            this.delete_modall1 = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查删除会员");
              return;
            }
            if(res.data.code === 1000){
              this.$Message.success('删除成功');
              this.get_list_client();

            }else if(res.data.code !== 1001){
              this.$Message.error(res.data.data);
            }else{
              this.$Message.error('删除失败');
            }
          }).catch(res=>{
            this.$Message.error("发生502，请核查删除会员");
            return;
          })
        },

        //获取子管理员列表（交易员列表）
        getListTrader(){
          let params ={
          };
          getListTrader(params).then(res=>{
            if(res.data.code === 1000){
              this.$Message.success('成功获取子管理员列表');
              this.member_data = res.data.data.list_trader
            }else{
              this.$Message.error(res.data.data);
            }
          })
            .catch((e) =>{
              this.$Message.error("获取数据失败");
            })
        },
        //获取子管理员列表（客户）列表
        getListTraderClient(traderClient){
          let params ={
            in_trader:traderClient
          };
          getListTraderClient(params).then(res=>{
            if(res.data.code === 1000){
              this.list_trader_client = res.data.data.list_client;

            }else{
              this.$Message.error(res.data.data);
            }
          })
            .catch((e) =>{
              this.$Message.error("获取数据失败");
            })
        },
        //添加子管理员（交易员）
        add_client_add(){
          let params ={
            trader:this.add_member_data.trader,
            googlecode:this.add_member_data.googlecode,
            googlekey:this.add_member_data.googlekey,
          };
          insertTrader(params).then(res=>{
            this.add_member_data = [];
            this.add_client_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查添加子管理员（交易员）");
              return;
            }
            if(res.data.code === 1000){
              this.$Message.success('添加成功');
              this.getListTrader()
            }else{
              this.$Message.error(res.data.data);
            }
          })
            .catch((e) =>{
              this.$Message.error("添加数据失败");
            })
        },
        //取消添加子管理员（交易员）
        add_client_cancel(){
          this.add_member_data = {
            client_number:'',
            googlekey:'',
            trader:'',
          }
        },
        google_add(){
          let params ={
            trader:this.add_member_data.trader,
            googlecode:this.add_member_data.googlecode,
            googlekey:this.add_member_data.googlekey,
          };
          updateTraderGooglekey(params).then(res=>{
            this.add_member_data = [];
            this.google_modall = false;
            if(res.status === 502){
              this.$Message.error("发生502，请核查google_add");
              return;
            }
            if(res.data.code === 1000){
              this.$Message.success('修改成功');
              this.getListTrader()
            }else{
              this.$Message.error(res.data.data);
            }
          })
            .catch((e) =>{
              this.$Message.error("修改数据失败");
            })
        },
        google_cancel(){
          this.googleCode = '';
        },
        assignUser_update(){
          let temp = '';
          this.temp_list_undistributed.forEach((res)=>{
            temp = temp  + res.key + ","
          });
          if(temp.length>0){
            temp = temp.substr(0, temp.length - 1)
          }
          let params ={
            trader:this.reset_trader,
            undistributed:temp,
            distributed:this.temp_list_distributed.length !== 0 ? this.temp_list_distributed.join(",") : ''
          };
          console.log(params)
          updateClientTrader(params).then(res=>{
            this.assignUser_modall = false;
            if(res.data.code === 1000){
              this.$Message.success('更新会员成功');
              this.getListTrader()
            }else{
              this.$Message.error("更新会员失败");
            }
          })
            .catch((e) =>{
              this.$Message.error("更新会员失败");
            })
        },
        assignUser_cancel(){
          this.googleCode = '';
        },
        //用户穿梭框显示名字
        assignUser_render(item){
          return item.label;
        },
        assignUser_handleChange(newTargetKeys){
          // console.log(newTargetKeys)
          this.temp_list_distributed = newTargetKeys;
        },
        //重置密码
        resetPasswords(){
          let params ={
            trader:this.reset_trader
          };
          defaultTraderPassword(params).then(res=>{
            if(res.data.code === 1000){
              this.getListTrader()
              this.$Message.success('重置成功');
            }else{
              this.$Message.error(res.data.data);
            }
          })
            .catch((e) =>{
              this.$Message.error("获取数据失败");
            })
        },
        //一键平仓
        end(){
          let params ={
            trader:this.reset_trader
          };
          end(params).then(res=>{
            this.end_modall = false;
            if(res.data.code === 1000){
              this.getListTrader()
              this.$Message.success('平仓成功');
            }else{
              this.$Message.error("平仓失败");
            }
          })
            .catch((e) =>{
              this.$Message.error("平仓失败");
            })
        },
        //平仓
        endAll(){
          let params ={
          };
          endAll(params).then(res=>{
            this.end_all_modall = false;
            if(res.data.code === 1000){
              this.getListTrader()
              this.$Message.success('平仓成功');
            }else{
              this.$Message.error("平仓失败");
            }
          })
            .catch((e) =>{
              this.$Message.error("平仓失败");
            })
        },
        //删除
        select_remove(){
          let params ={
            trader:this.reset_trader
          };
          console.log(params)
          deleteTrader(params).then(res=>{
            this.delete_modall2 = false;
            if(res.data.code === 1000){
              this.getListTrader()
              this.$Message.success('删除成功');
            }else{
              this.$Message.error("删除失败");
            }
          })
            .catch((e) =>{
              this.$Message.error("删除失败");
            })
        },
        //生成谷歌验证码密钥
        create_new_googlekey(){
          let code = ''
          let codeLength = 16;
          //所有候选组成验证码的字符，当然也可以用中文的
          let codeChars = new Array(2, 3, 4, 5, 6, 7,
            'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
          //循环组成验证码的字符串
          for (let i = 0; i < codeLength; i++)
          {
            //获取随机验证码下标
            let charNum = Math.floor(Math.random() * 32);
            //组合成指定字符验证码
            code += codeChars[charNum];
          }
          this.add_member_data.googlecode = code;
        },
        // 复制成功
        onCopy(e){
          this.$Message.success('复制成功');
          console.log(e);
        },
        // 复制失败
        onError(e){
          this.$Message.error('复制失败');
        },
        //获取尚未分配管理员的会员（客户）列表
        getListTraderNone(){
          let params ={
            trader:this.reset_trader
          };
          console.log(this.reset_trader)
          console.log(params)
          getListTraderNone(params).then(res=>{
            if(res.data.code === 1000){
              this.temp_list_undistributed = res.data.data.temp_list_undistributed;
              this.temp_list_distributed = res.data.data.temp_list_distributed;
              console.log(res.data.data)
              console.log(this.temp_list_undistributed)
              console.log(this.temp_list_distributed)
            }else{
              this.$Message.error(res.data.data);
            }
          })
            .catch((e) =>{
              this.$Message.error("获取数据失败");
            })
        },

        //获取策略参数设置
        get_strategy(){
          let params ={
            client:this.clientSelected, //用户ID（用户名）
            contract:this.contractSelected,//合约名称
          };
          getConfigBasic(params).then(res=>{
            if(res.data.code === 1000){
              this.strategy_parameter_data = []
              this.strategy_parameter_data.push(res.data.data)
            }
          })
        },
        //获取合约参数设置
        get_contract(){
          let params ={
            client:this.clientSelected, //用户ID（用户名）
            contract:this.contractSelected,//合约名称
          };
          getConfigNowOrIndex(params).then(res=>{
            if(res.data.code === 1000){
              this.contract_price_data  = res.data.data
            }
          })
        },
        //编辑策略参数设置保存
        strategy_parameter_save(){
          let params ={
            close_rate:this.add_strategy_parameter_data.close_rate,
            open_rate:this.add_strategy_parameter_data.open_rate,
            system_response_time:this.add_strategy_parameter_data.system_response_time,
          };
          updateConfigBasic(params).then(res=>{
            if(res.data.code === 1000){
              this.strategy_parameter_modall = false;
              this.$Message.success('成功');
              this.get_strategy()
            }else{
              this.$Message.error('失败');
            }
          })
        },
        //编辑策略参数设置取消
        strategy_parameter_cancel(){},
        //编辑合约参数设置保存
        contract_parameter_save(){
          let params ={
            contract:this.add_contract_parameter_data.contract, //合约
            price_type:this.add_contract_parameter_data.price_type,//合约价格类型
          };
          updateConfigNowOrIndex(params).then(res=>{
            if(res.data.code === 1000){
              this.contract_parameter_modall = false;
              this.$Message.success('成功');
              this.get_contract()
            }else{
              this.$Message.error('失败');
            }
          })
        },
        //编辑合约参数设置取消
        contract_parameter_cancel(){},

        //保存编辑会员
        update_client_save(){
          let params ={
            client_name: this.update_client.client_name,
            lowest_net_worth: this.update_client.lowest_net_worth,
            lowest_net_worth_type: this.update_client.lowest_net_worth_type,
          };
          if(!isNumberAndNone(params.lowest_net_worth)){
            this.$Message.error("最低净值不能是非法字符");
            return;
          }
          if(Number(params.lowest_net_worth)<0){
            this.$Message.error("最低净值不能小于0");
            return;
          }
          if(Number(params.lowest_net_worth)>this.update_client.swap_margin_balance){
            this.$Message.error("最低净值不能大于当前权益");
            return;
          }
          updateClient(params).then(res=>{
            this.update_client_modall = false;
            if(res.data.code === 1000){
              this.$Message.success('编辑成功');
              this.get_list_client();
            }else{
              this.$Message.error(res.data.data);
            }
            this.client_cancel()
          })
        },
        //取消编辑会员
        update_client_cancel(){
          this.update_client = {
            client_name:'',
            apikey:'',
            secretkey:'',
            lowest_net_worth:'',
            lowest_net_worth_type:'市价',
          };
        }
      },
      created(){
        this.get_list_client();
        this.getListTrader();

      },
      computed:{
        computed_client(){   //vux要监听对象
          return this.get_client()
        },
        computed_contract(){
          return this.get_contract()
        },
      },
      watch: {
        computed_client(){
          this.clientSelected = this.get_client();
        },
        computed_contract(){
          this.contractSelected = this.get_contract()
        },
      },
    }
</script>

<style scoped lang="less">
  .system{
    height: 880px;
    user-select: none;
    .tab_nav{
      display: flex;
      .tabs_tab{
        width: 154px;
        height: 52px;
        cursor: pointer;
        border-radius: 6px 6px 0px 0px;
        font-size: 16px;
        letter-spacing: 2px;
        text-align: center;
        line-height: 52px;
      }
      .extra{
        margin-left:auto;
        margin-right: 51px;
        margin-top: 10px;
        cursor: pointer;
        .ico_add{
          cursor: pointer;
          display: inline-block;
          width: 20px;
          height: 20px;
          background: url("/static/img/add to.png");
          vertical-align: middle;
          color: #397EED;
          margin-right: 5px;
        }
        label{
          cursor: pointer;
          display: inline-block;
          vertical-align: middle;
          font-size: 16px;
        }
      }
    }
    /deep/ .ivu-table:before{
      height: 0;
    }
    /deep/ .ivu-table th{
      border: 0;
      height: 48px;
    }
    /deep/ .ivu-table td{
      border: 0;
    }
  }

</style>
